import React from "react";

class Son extends React.Component {
    render() {
        return (
            <div>
                {this.props.a}
                <div>b: {this.props.b.b}</div>
                <button
                    onClick={() => {
                        this.props.fn("黑马程序员高薪就业");
                    }}>
                    点击
                </button>
            </div>
        );
    }
}
class AppClass extends React.Component {
    state = {
        name: "传智",
    };
    render() {
        return (
            <div>
                <p>{this.state.name}</p>
                {/* 父 -> 子传值：通过props传递 */}
                {/* 子 -> 父传值: 给子组件绑定一个函数，子组件调用函数通过参数传值 */}
                <Son
                    a="123"
                    b={{ b: 1234 }}
                    fn={(args) => {
                        this.setState({
                            name: args,
                        });
                    }}></Son>
            </div>
        );
    }
}

export default AppClass;
